﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Items_AddSubCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            
        }
    }
    
    [System.Web.Services.WebMethod]
    public static void SaveItemSubCategory(ItemSubCategory subcategory)
    {
        using (POSEntities db = new POSEntities())
        {
            try
            {

                subcategory.EntryBy = 1;
                subcategory.EntryDate = DateTime.Now;
                db.ItemSubCategories.Add(subcategory);
                db.SaveChanges();

            }
            catch (Exception ex)
            {

            }

        }
    }

    [System.Web.Services.WebMethod]
    public static List<usp_getSubCategory_Result> SearchSubCategories(int category_id)
    {
        using (POSEntities db = new POSEntities())
        {
            try
            {
                var Subcategory = db.usp_getSubCategory(category_id).ToList();
                return Subcategory;
            }
            catch (Exception ex)
            {
                return null;
            }

        }
    }

    [System.Web.Services.WebMethod]
    public static void DeleteSubCategory(int id)
    {
        using (POSEntities db = new POSEntities())
        {
            try
            {
                ItemSubCategory result = (from c in db.ItemSubCategories
                                       where c.SubCategoryId == id
                                       select c).SingleOrDefault();
                result.IsDeleted = true;
                db.SaveChanges();

            }
            catch (Exception ex)
            {

            }

        }
    }
}